package service

import (
	"seat-service/initialization"
	"seat-service/model"
	"seat-service/model/dto"
)

type SearchRecordService struct {
}

func (*SearchRecordService) Delete(id int) (err error) {
	err = initialization.DB.Where("id = ?", id).Delete(&model.SearchRecord{}).Error
	return
}

func (*SearchRecordService) Update(record *model.SearchRecord) (err error) {
	err = initialization.DB.Updates(record).Error
	return
}

func (*SearchRecordService) Get(record *model.SearchRecord) (err error) {
	err = initialization.DB.Where(record).First(record).Error
	return
}

func (*SearchRecordService) GetByPage(page *dto.PageParam) (record []model.SearchRecord, err error) {
	err = initialization.DB.Offset((page.PageNo-1)*page.PageSize).Limit(page.PageSize).Where("student_id = ?", page.Data).Order("updated_at DESC").Find(&record).Error
	return
}

func (*SearchRecordService) Save(record *model.SearchRecord) (err error) {
	err = initialization.DB.Save(record).Error
	return
}
